// index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    region:['安徽省','芜湖市','镜湖区'],
    idlocation:'101010100',
    now:{icon:999}
  },
  regionChange:function(e){
    this.setData({region:e.detail.value});
    this.getLocationId();
    this.getWeather();
  },
  getWeather:function(){
    var that = this;
    wx.request({
      url:'https://devapi.qweather.com/v7/weather/now',
      data:{
        location:that.data.idlocation,
        key:'4bf79e024e6a45c7967b4835744b3caf'
      },
      success:function(res){
        that.setData({now:res.data.now})
      }
    })
  },
  getLocationId:function(){
    var that = this;
    wx.request({
      url:'https://geoapi.qweather.com/v2/city/lookup',
      data:{
        location:that.data.region[2],
        key:'4bf79e024e6a45c7967b4835744b3caf'
      },
      success:function(res){
        that.setData({idlocation:res.data.location[0].id});
        //console.log(that.data.region[2]);
        //console.log(that.data.idlocation);
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //this.getWeather();
    //this.setData({now:{icon:999}});
    this.getLocationId();
    this.getWeather();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})
